<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>轮播广告列表</title>
    <link rel="stylesheet" href="css/font-awesome.min.css"/>
    <link rel="stylesheet" href="css/font-awesome-ie7.min.css"/>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <link href="css/jquery.datetimepicker.css" rel="stylesheet">
    <link rel="stylesheet" href="css/admin.css"/>

    <link rel="stylesheet" type="text/css" href="css/paging.css">

    <!--[if lt IE 9]>
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <![endif]-->
    <!--[if lt IE 10]>
    <script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/jquery-placeholder/2.0.8/jquery.placeholder.min.js"></script>
    <![endif]-->
</head>
<body>
<div id="gray_bg"></div>
<!-- 编辑分类开始 -->
<div id="editDiadog" class="diadog">
    <div class="diadog-tit">
        <div class="row">
            <div class="col-md-11" id="diadogTitle"><span>添加图片</span></div>
            <div class="col-md-1 close"><span>×</span></div>
        </div>
    </div>
    <div class="diadog-con">
        <div class="form-horizontal" role="form">
            <div class="form-group" id="uploadImg">
                <label for="inputPassword3" class="col-md-3 control-label"><span
                        style="color: #e4393c">*</span>广告图片:</label>
                <div class="col-sm-4">
                    <button style="margin-bottom: 5px; margin-left: 0px" type="button" class="btn btn-default">上传图片
                    </button>
                    <input style="width:300px !important;height:60px !important;position: absolute !important;z-index: 100 !important;filter:alpha(opacity=0)!important;-moz-opacity:0 !important;-khtml-opacity:0 !important; opacity: 0 !important;top:0px; !important;cursor: pointer; left: 0px !important;"
                           id="pickfiles" type="file" class="form-control">
                    <input id="avatar" type="hidden" class="form-control">
                </div>
                <label class="control-label">(宽:414px，高:165px)</label>
            </div>
            <div class="form-group" id="imageShow">
                <label for="inputPassword3" class="col-md-3 control-label">图片:</label>
                <span class="col-sm-2" style=" color: #000; margin-top: 15px;"><img id="imgName"
                                                                                    style="width: 276px;height: 110px;"></span>
            </div>
            <div class="form-group" id="sort">
                <label for="inputPassword3" class="col-md-3 control-label">修改排序:</label>
                <div class="col-sm-9">
                    <input id="sortIndex" type="text" class="form-control">
                </div>
            </div>
            <div class="form-group" id="btn">
                <div class="col-sm-offset-3 col-sm-9">
                    <button id="saveClass" type="submit" class="btn btn-danger">保存</button>
                    <button id="editClass" type="submit" class="btn btn-danger">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 编辑分类结束 -->
<!-- 删除分类开始 -->
<div id="deleteDiadog" class="diadog">
    <div class="diadog-tit">
        <div class="row">
            <div class="col-md-11"><span id="delTitle">确定删除图片？</span></div>
            <div class="col-md-1 close"><span>×</span></div>
        </div>
    </div>
    <div class="diadog-con" style="padding:30px 0">

        <div class="form-horizontal" role="form">
            <div class="row">
                <div class="col-md-12"></div>

                <div class="form-group" style="text-align: center;">
                    <div class="col-md-1"></div>
                    <div class="col-md-2">
                        <button id="enableSure" type="submit" class="btn btn-primary">确 定</button>
                    </div>
                    <div class="col-md-2">
                        <button id="btn-default" type="submit" class="btn btn-default">取 消</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 删除分类结束 -->
<!-- header start -->
<div id="header" class="header">

</div>
<!-- header end -->
<!-- usercenter start -->
<div class="usercotent">
    <div id="center-left"></div>
    <div class="usercotentr floatr">
        <div class="user-tit" style="margin-bottom:10px">
            <h3>轮播广告列表</h3>
        </div>
        <div class="usercotent-con">
            <!--<div class="col-md-2" style="width: 140px !important;">-->
            <!--<input id="search_keyvalue" class="inputStory" type="text"-->
            <!--style="width:140px !important;height: 34px !important;" placeholder="关键字">-->
            <!--</div>-->
            <!--<div class="col-md-1">-->
            <!--<button id="order_search" type="button" class="btn btn-success">查询</button>-->
            <!--</div>-->
            <div class="col-md-12">
                <button id="addCategory" type="button" class="btn btn-danger pull-right">添加图片</button>
            </div>


            <div class="down">
                <table class="table table-bordered table-hover table-condensed">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>广告图片</th>
                        <th>图片顺序</th>
                        <th>操作</th>
                    </tr>
                    </thead>

                    <tbody id='results'>

                    </tbody>

                </table>
            </div>
            <!-- page start -->
            <!--<nav class="totalpage floatr">-->
            <!--<span>总共</span><strong id="totalpage"></strong><span>条</span>-->
            <!--<div id="pageTool" style="margin-top:20px;"></div>-->
            <!--</nav>-->
            <!--<div class="clear"></div>-->
            <!-- page end -->
        </div>

    </div>
    <div class="clear"></div>
</div>

<!-- usercenter end -->

<!-- footer start -->
<div class="footer">
    <div class="bot">
        <p style="padding-top: 10px; text-align: center">Copyright (C) 都能印 2014-2016, all Rights Reserved |
            豫ICP备14024464号-1 | 增值电信业务经营许可证：豫B2-20150019</p>
        <p class="authentication" style="padding-bottom: 10px; padding-top: 10px;">
            <img src="img/footer1.png" alt="">
            <img src="img/footer2.png" alt="">
            <img src="img/footer3.png" alt="">
            <img src="img/footer4.png" alt="">
            <img src="img/footer5.png" alt="">
        </p>
    </div>
</div>
<!-- footer end -->
<script src="js/jquery.min-1-11-3.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/widget/myDataGrid.js"></script>
<script src="js/widget/admin.js"></script>
<script type="text/javascript" src="js/query.js"></script>
<script type="text/javascript" src="js/paging.js"></script>
<script type="text/javascript" src="bower_components/plupload/js/plupload.full.min.js"></script>
<script type="text/javascript" src="js/ui.js"></script>
<script type="text/javascript" src="js/qiniu.min.js"></script>
<script type="text/javascript" src="js/upload.js"></script>
<script type="text/javascript">
    var id;
    //开始
    $(function () {
        initSideAccMenu("合伙人管理", "合伙人列表");
//        获取数据
        $.post("apis/user/getpartnerimagelist", {"partnerId": query("partnerId")}, function (res) {
            var data = res.data;
            var sHtml = "";
            var j = 0;
            for (var i = 0; i < data.length; i++) {
                j += 1;
                sHtml += '<tr>' +
                    '<td>' + j + '</td>' +
                    '<td><img src="' + data[i].imageUrl + '" alt="" style="width:200px ;height: 80px"></td>' +
                    '<td>'+data[i].sortIndex+'</td>' +
                    '<td>' +
                    '<a href="javascript:;" onclick="editIndex(' + data[i].id + ','+data[i].sortIndex+')">调整顺序</a>' +
                    '&nbsp&nbsp&nbsp' +
                    '<a href="javascript:;" onclick="del(' + data[i].id + ')">删除</a>' +
                    '</td>'
                '</tr>'
            }
            $("#results").append(sHtml);
        })
    });
    //    添加图片
    $("#addCategory").click(function () {
        $("#gray_bg").show();
        $("#gray_bg").css({"height": $(document).height()});
        $("#editDiadog").show();
        $("#editDiadog").center();

        $("#sort").siblings().show();
        $("#sort").hide();
        $("#saveClass").show();
        $("#editClass").hide();
    })
    $("#saveClass").click(function () {
        var imageUrl = $("#avatar").val();
        var data = {
            partnerId: query("partnerId"),
            imageUrl: imageUrl
        }
        $.ajax({
            url: "apis/user/addpartnerimage",
            type: 'post',
            data: {
                "image": JSON.stringify(data)
            },
            dataType: 'json',
            success: function (data, status, xhr) {
                if (data.httpCode == 200) {
                    $("#gray_bg").hide();
                    $("#editDiadog").hide();
                    window.location.reload();
                } else {
                    alert(data.msg);
                }
            }
        })
    })
    //    调整顺序
    var partId;
    function editIndex(id,index) {
        partId = id;
        $("#gray_bg").show();
        $("#gray_bg").css({"height": $(document).height()});
        $("#editDiadog").show();
        $("#editDiadog").center();
        $("#diadogTitle").html("修改排序")

        $("#sort").show();
        $("#sort").siblings().hide();
        $("#btn").show();
        $("#saveClass").hide();
        $("#editClass").show();
        $("#sortIndex").val(index);
    }
    $("#editClass").click(function () {
        var data = {
            id:partId,
            partnerId:query("partnerId"),
            sortIndex:$("#sortIndex").val()
        }
        $.ajax({
            url: "apis/user/updatepartnerimagesort",
            type: 'post',
            data: {
                "image": JSON.stringify(data)
            },
            dataType: 'json',
            success: function (data, status, xhr) {
                if (data.httpCode == 200) {
                    $("#gray_bg").hide();
                    $("#editDiadog").hide();
                    window.location.reload();
                } else {
                    alert(data.msg);
                }
            }
        })
    })
    //    删除
    function del(id) {
        partId = id;
        $("#gray_bg").show();
        $("#gray_bg").css({"height": $(document).height()});
        $("#deleteDiadog").show();
        $("#deleteDiadog").center();
    }
    $("#enableSure").click(function () {
        var data = {
            id:partId,
            partnerId:query("partnerId")
        }
        $.ajax({
            url: "apis/user/deletepartnerimage",
            type: 'post',
            data: {
                "image": JSON.stringify(data)
            },
            dataType: 'json',
            success: function (data, status, xhr) {
                if (data.httpCode == 200) {
                    $("#gray_bg").hide();
                    $("#deleteDiadog").hide();
                    window.location.reload();
                } else {
                    alert(data.msg);
                }
            }
        })
    })

    //  垂直居中
    jQuery.fn.center = function () {
        this.css("position", "absolute");
        this.css("top", ( $(window).height() - this.height() ) / 2 + $(window).scrollTop() + "px");
        this.css("left", ( $(window).width() - this.width() ) / 2 + $(window).scrollLeft() + "px");
        return this;
    }
    function query(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null)return unescape(r[2]);
        return "";
    }
    $(".close,#btn-default").click(function () {
        $("#gray_bg").hide();
        $("#editDiadog").hide();
        $("#deleteDiadog").hide();

        $("#typeName").val("");
        $("#avatar").val("");
        $("#description").val("");
        $("#remark").val("");
        $("#imgName").removeAttr("src");
    })
</script>
</body>
</html>